package com.simin.base.appnet.encrypt;

import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.TypeAdapter;

import java.io.IOException;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Converter;

/**
 * Created by wsm on 2016/5/31.
 * <p>
 * 自定义请求RequestBody
 */
public class JsonRequestBodyConverter<T> implements Converter<T, RequestBody> {
//    private static final MediaType MEDIA_TYPE = MediaType.parse("application/x-www-form-urlencoded; charset=UTF-8");
    private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");
    private final Gson gson;
    private final TypeAdapter<T> adapter;

    /**
     * 构造器
     */

    public JsonRequestBodyConverter(Gson gson, TypeAdapter<T> adapter) {
        this.gson = gson;
        this.adapter = adapter;
    }


    @Override
    public RequestBody convert(T value) throws IOException {

        Log.i("log","reques" + "传递没加密的参数：" + value.toString());


        return RequestBody.create(MEDIA_TYPE, value.toString());

        //加密
//        String postBody = XXTEA.encryptWithBase64(value.toString().getBytes(),
//                HttpConstant.URL_CipherKey.getBytes());

//        PickerLog.i("log","reques" + "传递加密的参数：" + postBody);


    }


}
